package com.wiscamp.ninechapters.problems.infrastructure.mappers.exams;

import com.wiscamp.ninechapters.problems.infrastructure.po.exams.ScoringRuleView;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.data.jpa.repository.Query;
import org.springframework.stereotype.Repository;

import java.util.Collection;

@Repository
public interface ScoringRuleViewMapper extends JpaRepository<ScoringRuleView, Long>, JpaSpecificationExecutor<ScoringRuleView> {

    /**
     * 通过考试编号题型编号和问题类型编号获取评分规则
     *
     * @param examId
     * @param problemTypeId
     * @param questionTypeId
     * @return
     */
    @Query(value = "select p from ScoringRuleView p where p.examId = :examId and p.problemTypeId = :problemTypeId and p.questionTypeId = :questionTypeId")
    ScoringRuleView findByExamAndType(long examId, long problemTypeId, long questionTypeId);

    @Query(value = "select p from ScoringRuleView p where p.examId = :examId")
    Collection<ScoringRuleView> findListByExam(long examId);
}